package com.jeesite.modules.backlog.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.common.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.backlog.entity.DcSupBacklog;
import com.jeesite.modules.backlog.service.DcSupBacklogService;

import java.util.List;

/**
 * 待办事项表Controller
 * @author zrr
 * @version 2022-11-21
 */
@Controller
@RequestMapping(value = "${adminPath}/backlog/dcSupBacklog")
public class DcSupBacklogController extends BaseController {

	@Autowired
	private DcSupBacklogService dcSupBacklogService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupBacklog get(String id, boolean isNewRecord) {
		DcSupBacklog backlog = dcSupBacklogService.get(id, isNewRecord);
		if(StringUtils.isNotBlank(backlog.getId())){
			backlog.setBacklogHref(backlog.getBacklogHref().substring(2));
		}
		return backlog;
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("backlog:dcSupBacklog:view")
	@RequestMapping(value = {"list", ""})
	public String list(DcSupBacklog dcSupBacklog, Model model) {
		model.addAttribute("dcSupBacklog", dcSupBacklog);
		return "modules/backlog/dcSupBacklogList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("backlog:dcSupBacklog:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupBacklog> listData(DcSupBacklog dcSupBacklog, HttpServletRequest request, HttpServletResponse response) {
		dcSupBacklog.setPage(new Page<>(request, response));
		Page<DcSupBacklog> page = dcSupBacklogService.findPage(dcSupBacklog);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("backlog:dcSupBacklog:view")
	@RequestMapping(value = "form")
	public String form(DcSupBacklog dcSupBacklog, Model model) {
		model.addAttribute("dcSupBacklog", dcSupBacklog);
		return "modules/backlog/dcSupBacklogForm";
	}

	@RequestMapping(value = "detail")
	public String detail(DcSupBacklog dcSupBacklog, Model model) {
		return renderResult(Global.TRUE, text("成功！"),dcSupBacklog);
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("backlog:dcSupBacklog:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DcSupBacklog dcSupBacklog) {
		dcSupBacklogService.save(dcSupBacklog);
		return renderResult(Global.TRUE, text("保存待办事项表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("backlog:dcSupBacklog:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupBacklog dcSupBacklog) {
		dcSupBacklogService.delete(dcSupBacklog);
		return renderResult(Global.TRUE, text("删除待办事项表成功！"));
	}

	@RequestMapping(value = "getPage")
	@ResponseBody
	public Page<DcSupBacklog> getPage(DcSupBacklog dcSupBacklog, HttpServletRequest request, HttpServletResponse response) {
		dcSupBacklog.setPage(new Page<>(request, response));
		Page<DcSupBacklog> page = dcSupBacklogService.getPage(dcSupBacklog);
		return page;
	}

	@RequestMapping(value = "getList")
	@ResponseBody
	public List<DcSupBacklog> getList(DcSupBacklog dcSupBacklog) {
		return dcSupBacklogService.getList(dcSupBacklog);
	}

	@RequestMapping(value = {"backlogView", ""})
	public String backlogView(DcSupBacklog dcSupBacklog, Model model) {
		model.addAttribute("dcSupBacklog", dcSupBacklog);
		return "modules/home/backlogView";
	}

	@RequestMapping(value = {"backlogList", ""})
	public String backlogList(DcSupBacklog dcSupBacklog, Model model) {
		model.addAttribute("dcSupBacklog", dcSupBacklog);
		return "modules/home/backlogList";
	}

	@RequestMapping(value = {"backlogList1", ""})
	public String backlogList1(DcSupBacklog dcSupBacklog, Model model) {
		model.addAttribute("dcSupBacklog", dcSupBacklog);
		return "modules/home/backlogList1";
	}

	/**
	 * 任务详情查看各个牵头单位的进度
	 * @param dcSupBacklog
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "getDetailPage")
	@ResponseBody
	public Page<DcSupBacklog> getDetailPage(DcSupBacklog dcSupBacklog, HttpServletRequest request, HttpServletResponse response) {
		dcSupBacklog.setPage(new Page<>(request, response));
		Page<DcSupBacklog> page = dcSupBacklogService.getDetailPage(dcSupBacklog);
		return page;
	}
}